package com.guanyong.webapi.controllers.api;

import com.guanyong.model.UserBaseModel;
import com.guanyong.model.VideoBarrageModel;
import com.guanyong.services.VideoBarrageService;
import com.guanyong.services.VideoBuyLogServices;
import com.guanyong.utils.Comm.ResultCode;
import com.guanyong.utils.Comm.ResultObject;
import com.guanyong.webapi.handle.UserHandle;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created by mxk on 2017/7/5.
 */

@RestController
@RequestMapping("/api/videobarrage/")
public class VideoBarrageApi {
    @Autowired
    UserHandle userHandle;

    @Autowired
    VideoBarrageService videoBarrageService;

    @RequestMapping(value = "addbarrage", method = RequestMethod.POST)
    ResultObject<Integer> addBarrage(HttpServletRequest request,
                                     @RequestParam Integer classtype,
                                     @RequestParam String objectid,
                                     @RequestParam String content,
                                     @RequestParam String barragetime) {
        ResultObject<Integer> resultObject=new ResultObject<Integer>();
        UserBaseModel userBaseModel = userHandle.getCurUser(request);
        if (userBaseModel != null && !userBaseModel.getfId().equals("")) {
            VideoBarrageModel videoBarrageModel=new VideoBarrageModel();
            videoBarrageModel.setfClasstype(classtype);
            videoBarrageModel.setfObjectid(objectid);
            videoBarrageModel.setfUserid(userBaseModel.getfId());
            videoBarrageModel.setfContent(content);
            videoBarrageModel.setfBarragetime(barragetime);
            resultObject=videoBarrageService.AddVideoBarrage(videoBarrageModel);
        }
        else{
            resultObject.setCode(ResultCode.NoLogin);
        }
        return resultObject;
    }

    @RequestMapping(value = "getbarragelist", method = RequestMethod.GET)
    ResultObject<List<VideoBarrageModel>> GetVideoBarrageList( @RequestParam Integer classtype,
                                                               @RequestParam String objectid,
                                                               @RequestParam String  betime){
        List<VideoBarrageModel>  list= videoBarrageService.GetVideoBarrage(classtype,objectid,
                betime);
        ResultObject<List<VideoBarrageModel>> resultObject=new
                ResultObject<List<VideoBarrageModel>>();

        resultObject.setResult(list);
        return resultObject;
    }
}
